﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TuanJuAPIManager
{
    public class CatagoryGroup
    {
        public Category CatagoryGroupType { set; get; }

        public string CatagoryGroupName { set; get; }

        public IEnumerable<Deal> CatagoryDeals { set; get; }

        public string CatagoryDescription { set; get; }

        public string CatagoryImage { set; get; }

        public CatagoryGroup(Category catagoryGroupType, string catagoryGroupName, string catagoryDescription, string catagoryImage)
        {
            this.CatagoryGroupType = catagoryGroupType;
            this.CatagoryGroupName = catagoryGroupName;
            this.CatagoryDescription = catagoryDescription;
            this.CatagoryImage = catagoryImage;
        }
    }

    public class Group
    {
        private static CatagoryGroup saleGroup = new CatagoryGroup(Category.网络购物, "购物", "网络购物类抢购中", "Assets/shopping.png");

        private static CatagoryGroup foodGroup = new CatagoryGroup(Category.美食, "美食", "经典美食类抢购中", "Assets/goodfood.png");

        private static CatagoryGroup gameGroup = new CatagoryGroup(Category.休闲娱乐, "休闲娱乐", "休闲娱乐类抢购中", "Assets/lifegame.png");

        private static CatagoryGroup hotelGroup = new CatagoryGroup(Category.旅游, "酒店旅游", "旅游类抢购中", "Assets/play.png");

        private static CatagoryGroup lifeGroup = new CatagoryGroup(Category.生活, "生活服务", "生活类抢购中", "Assets/life.png");

        private static CatagoryGroup othersGroup = new CatagoryGroup(Category.其他, "其他", "其他类抢购中", "Assets/server.png");

        private static List<CatagoryGroup> showGroups = new List<CatagoryGroup>();

        private static List<CatagoryGroup> allGroups = new List<CatagoryGroup>();

        public IEnumerable<CatagoryGroup> AllGroups 
        {
            get { return allGroups; }
        }

        public static List<CatagoryGroup> ShowGroups
        {
            get
            {
                showGroups.Clear();
                showGroups.Add(saleGroup);
                showGroups.Add(foodGroup);
                showGroups.Add(gameGroup);
                showGroups.Add(hotelGroup);
                showGroups.Add(lifeGroup);
                showGroups.Add(othersGroup);
                return showGroups;
            }
        }

        public static async Task<IEnumerable<CatagoryGroup>> InitializeGroup(Category categoryType)
        {
            allGroups.Clear();
            TuanApi tuanApi = TuanApi.GetInstance(new Settings().DefaultCity);
            switch (categoryType)
            {
                case Category.All:
                    saleGroup.CatagoryDeals = await tuanApi.GetDeals(Category.网络购物);
                    if (saleGroup.CatagoryDeals.Count() > 0)
                    {
                        allGroups.Add(saleGroup);
                    }
                    foodGroup.CatagoryDeals = await tuanApi.GetDeals(Category.美食);
                    if (foodGroup.CatagoryDeals.Count() > 0) 
                    {
                        allGroups.Add(foodGroup);                     
                    }
                    gameGroup.CatagoryDeals = await tuanApi.GetDeals(Category.休闲娱乐);
                    if (gameGroup.CatagoryDeals.Count() > 0) 
                    {
                        allGroups.Add(gameGroup);
                    }
                    hotelGroup.CatagoryDeals = await tuanApi.GetDeals(Category.旅游);
                    if (hotelGroup.CatagoryDeals.Count() > 0)
                    {
                        allGroups.Add(hotelGroup);
                    }
                    lifeGroup.CatagoryDeals = await tuanApi.GetDeals(Category.生活);
                    if (lifeGroup.CatagoryDeals.Count() > 0)
                    {
                        allGroups.Add(lifeGroup);
                    }
                    othersGroup.CatagoryDeals = await tuanApi.GetDeals(Category.其他);
                    if (othersGroup.CatagoryDeals.Count() > 0)
                    {
                        allGroups.Add(othersGroup);
                    }
                    break;
                case Category.网络购物:
                    saleGroup.CatagoryDeals = await tuanApi.GetDeals(Category.网络购物);
                    allGroups.Add(saleGroup);
                    break;
                case Category.美食:
                    foodGroup.CatagoryDeals = await tuanApi.GetDeals(Category.美食);
                    allGroups.Add(foodGroup);
                    break;
                case Category.休闲娱乐:
                    gameGroup.CatagoryDeals = await tuanApi.GetDeals(Category.休闲娱乐);
                    allGroups.Add(gameGroup);
                    break;
                case Category.旅游:
                    hotelGroup.CatagoryDeals = await tuanApi.GetDeals(Category.旅游);
                    allGroups.Add(hotelGroup);
                    break;
                case Category.生活:
                    lifeGroup.CatagoryDeals = await tuanApi.GetDeals(Category.生活);
                    allGroups.Add(lifeGroup);
                    break;
                case Category.其他:
                    othersGroup.CatagoryDeals = await tuanApi.GetDeals(Category.其他);
                    allGroups.Add(othersGroup);
                    break;
                default:
                    break;
            }
            return allGroups;
        }
    }
}
